using System;
using System.Collections.Generic;
using System.Text;
using WebCrawlerTools.page;

namespace WebCrawlerTools.control
{
    public class ControlCenter
    {
        private PHomePage homePage;
    
        public PHomePage HomePage
        {
            get
            {
                return homePage;
            }
            set
            {
                homePage = value;
            }
        }
        private SEngine engine;
        public SEngine Engine
        {
            get
            {
                return engine;
            }
            set
            {
                engine = value;
            }
        }

        //private System.Windows.Forms.Timer timer;
        //-------------------------------------------------------------------------------------

        public void EventInitialize()
        {
            //timer = new System.Windows.Forms.Timer();
            //timer.Enabled = false;
            //timer.Interval = 1000;
            //timer.Tick += new EventHandler(this.StartTask);


            engine.Net.WebLoaded += new EventHandler(this.OnOnePageCompleted);

            engine.SearchPageInputed += new EventHandler(this.OnSearchPageInputed);
            engine.SearchPageSearched += new EventHandler(this.OnSearchPageSearched);
            engine.ListPageLoadCompleted += new EventHandler(this.OnListPageLoadCompleted);
            engine.ListPageAnalysisCompleted += new EventHandler(this.OnListPageAnalysisCompleted);
            engine.DetailPageLoadCompleted += new EventHandler(this.OnDetailPageLoadCompleted);
            engine.DetailPageAnalysisCompleted += new EventHandler(this.OnDetailPageAnalysisCompleted);
            engine.GoBackToListPageCompleted += new EventHandler(this.OnGoBackToListPageCompleted);
            engine.DetailPageAllCompleted += new EventHandler(this.OnDetailPageAllCompleted);
            engine.NextListPageLoadCompleted += new EventHandler(this.OnNextListPageLoadCompleted);
            engine.ListPageAllCompleted += new EventHandler(this.OnListPageAllCompleted);
            
        }

        public void StartEngine()
        {
            //******************** Just for get Chatter User ********************
            engine.HomePage = this.HomePage;
            //engine.SearchPageInput();
            engine.ListPageAnalysis();
            //******************** Just for get Chatter User ********************
        }

        //public void StartTask(object sender, EventArgs e)
        //{
        //    timer.Enabled = false;
        //}

        public void OnOnePageCompleted(object sender, EventArgs e)
        {
            engine.OnOnePageCompleted();
        }

        public void OnSearchPageInputed(object sender, EventArgs e)
        {
            //timer.Enabled = true;
            engine.SearchPageStartSearch();
        }

        public void OnSearchPageSearched(object sender, EventArgs e)
        {

        }

        public void OnListPageLoadCompleted(object sender, EventArgs e)
        {
            engine.ListPageAnalysis();
        }

        public void OnListPageAnalysisCompleted(object sender, EventArgs e)
        {
            //******************** Just for get Chatter User ********************
            //engine.OpenDetailPage();
            engine.GoToNextListPage();
            //******************** Just for get Chatter User ********************
        }

        public void OnDetailPageLoadCompleted(object sender, EventArgs e)
        {
            engine.DetailPageAnalysis();
        }

        public void OnDetailPageAnalysisCompleted(object sender, EventArgs e)
        {
            engine.GoBackToListPage();
        }

        public void OnGoBackToListPageCompleted(object sender, EventArgs e)
        {
            engine.GoToNextDetailPage();
        }

        public void OnDetailPageAllCompleted(object sender, EventArgs e)
        {
            engine.GoToNextListPage();
        }

        public void OnNextListPageLoadCompleted(object sender, EventArgs e)
        {
            engine.ListPageAnalysis();
        }

        public void OnListPageAllCompleted(object sender, EventArgs e)
        {
            //engine.GoBackToSearchPage();
        }
    }
}
